
import {
  queryPromotionCommissionList
} from "../../../../service/jb_promotion_service"
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    menuTop: app.globalData.menuButton.top,
    menuHeight: app.globalData.menuButton.height,
    topSwiperIndex: 0,
    requestData: {
      page: 1,
      limit: 20,
    },
    page: 1,
    limit: 10,
    dataList: [


    ],
    dateLimit: '',
    orderStatusOptions: [
      {
        text: "全部",
        value: ""
      },
      {
        text: "预收益",
        value: 1
      },
      {
        text: "待提现",
        value: 2
      },

      {
        text: "可提现金额",
        value: 3
      },


      {
        text: "失效收益",
        value: 4
      },

    ],
    isShowLoading: false,//加载状态出现
    isBottomShow: false,//是否没有更多数据了
    refreshFlag: false,
    totalCommission: 0,
    commissionStatus: "",
    statusMap: {
      0: '待发货',
      1: '待收货',
      2: '待评价',
      3: '已完成',
      4: '已退款',
    },
    refundStautsMap: {
      1: '退款申请中',
      2: '已退款'
    },
    commissonStatusMap: {
      0: '预收益',
      1: '预收益',
      2: '待提现',
      3: '已提现',
      4: '退款',
      5: '提现中',
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.queryPromotionCommissionList("refresh");
    this.setData({
      totalCommission: options.commission,
    })
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  //下拉筛选状态变化
  dropdownMenuChange(e) {
    console.log("JJLog:哈哈哈哈：" + JSON.stringify(e));
    this.setData({
      commissionStatus: e.detail,
      page: 1,
      isBottomShow: false,
    })
    this.queryPromotionCommissionList('refresh')
  },

  queryPromotionCommissionList(type) {
    wx.showLoading();
    queryPromotionCommissionList(this.data.page, this.data.limit, this.data.commissionStatus, this.data.dateLimit).then(res => {
      wx.hideLoading();
      if (res.code == 200 && res.data) {
        let arr = (type == 'refresh' ? [] : this.data.dataList || []);
        arr = arr.concat(res.data.list || [])
        this.setData({
          dataList: arr,
          refreshFlag: false,
          isShowLoading: false,
          totalCount: res.data.count,
          isBottomShow: res.data.totalPage == this.data.page ? true : false,
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || '加载失败',
        icon: "none"
      })
      if (this.data.page != 1) {
        this.setData({
          page: this.data.page - 1
        })
      }
      this.setData({
        refreshFlag: false,
      })
      console.error('JJLog:queryPromotionCommissionList', err);
    })
  },

  //下拉刷新
  handleRefresh() {
    // TODO
    this.setData({
      page: 1,
      isBottomShow: false,
      refreshFlag: true,
    })
    this.queryPromotionCommissionList('refresh');
  },
  handleLoadmore() {
    console.log('加载更多');
    if (this.data.isBottomShow) {
      return;
    }
    this.setData({
      isShowLoading: true,
      page: this.data.page + 1
    })
    this.queryPromotionCommissionList()
  },
  //时间筛选回调
  timeConfirmAction(e) {
    console.log("JJLog:结果是:" + JSON.stringify(e));
    // {"type":"timeConfirmAction","timeStamp":34363,"target":{"id":"","dataset":{}},"currentTarget":{"id":"","dataset":{}},"mark":{},"detail":{"showTimeText":"2022-10-05 - 2022-10-12","startTimeStr":"2022-10-05 00:00:00","endTimeStr":"2022-10-12 23:59:59"},"mut":false}
    if (e.detail.startTimeStr == '') {
      this.setData({
        dateLimit: '',
        page: 1,
        isBottomShow: false
      })
      this.queryPromotionCommissionList('refresh')
      return;
    }
    let startAt = e.detail.startTimeStr.split(' ')[0];
    let endAt = e.detail.endTimeStr.split(' ')[0];
    this.setData({
      dateLimit: startAt + "," + endAt,
      page: 1,
      isBottomShow: false
    })
    this.queryPromotionCommissionList('refresh');
    // console.log('JJLog:最终时间：' + this.data.requestParams.dateLimit)
  },
  //复制订单号
  copyOrderNo(e) {
    let text = e.currentTarget.dataset.text;
    wx.setClipboardData({
      data: text,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '订单号复制成功',
              icon: 'none'
            })
          },
          fail: function (err) {
            wx.showToast({
              title: '复制失败',
              icon: "none"
            })
          }
        })
      }
    })
  },

})